﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Threading.Tasks;
using System.Windows;
using WinForms = System.Windows.Forms;

namespace PeerComLink
{
    public partial class App : Application
    {
        static RunningData _rdInstance;
        public static RunningData RunningData
        {
            get
            {
                return _rdInstance;
            }
        }

        public static int Mode { get; private set; }

        public const int Channels = 1;
        public const int SamplesPerSecond = 48000;
        public const int BitsPerSample = 16;

        public static WaveFormatParam WaveFormatParams = new WaveFormatParam(SamplesPerSecond, Channels, BitsPerSample);

        void App_Startup(object sender, StartupEventArgs e)
        {

            if (e.Args.Length > 0)
                Mode = int.Parse(e.Args[0]);
            else
                Mode = 0;
            StartComLink();
        }

        private void StartComLink()
        {
            _rdInstance = new RunningData();

            this.MainWindow = new MainView();

            WinForms.NotifyIcon ni = new WinForms.NotifyIcon();
            ni.Icon = PeerComLink.Properties.Resources.casque_micro;
            ni.Visible = true;
            ni.Click +=
                (object sender2, EventArgs args) =>
                {
                    MainWindow.Show();
                    MainWindow.WindowState = WindowState.Normal;
                };
            ni.ContextMenu = new WinForms.ContextMenu(new WinForms.MenuItem[] {
                new WinForms.MenuItem("Close", (sender2, args) => {
                    Application.Current.Shutdown();
                })
            });

            MainWindow.Closing += (object sender2, CancelEventArgs args) =>
            {
                MainWindow.Hide();
                args.Cancel = true;
            };

            MainWindow.Show();
        }
    }
}
